#include "player.h"
#include "resource.h"

void player::init(float _x, float _y, float _z, int _numlifes, float _max_y,float _speed)
{
    //Give the player the position.
    x = _x;
    y = _y;
    z = _z;
    max_y = _max_y; 
    speed = _speed;
    
    oldy = y;
    
    s_bitmap temp;
    
    //Load the player model with texture.
    LoadMesh("models//player.obj",&model);
    DML_LoadBitmap("texture_l.tga",&temp);
    textureid=DML_CreateTextureGL(temp);
    DML_DeleteBitmap(&temp);
    
    //maximale levens die de speler krijgt.
    numlifes = _numlifes;
}

int player::update()
{
    //input player:
    DML_input_getkeys(&key,&key_trig);
    
    if(x > -10.20f) { if(key == 8) x-=speed; }
    if(x < 10.20f) { if(key == 4) x+=speed;}
    
    if(y < (oldy+max_y) && key == 1) { y+=speed;  }
    if(y >= oldy && key == 2) { y-=speed; }
    
    //shoot
    if(key == 16) return 1;
    
}

void player::draw()
{
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glScalef(0.05f,0.05f,0.05f);
    glTranslatef(x,y,z);
    glBindTexture(GL_TEXTURE_2D,textureid);
    drawobject(&model);
    
}

void player::gameover()
{
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glScalef(0.1f,0.1f,0.1f);
    glTranslatef((x+3.5f),(y+10.0f),z);
    glBindTexture(GL_TEXTURE_2D,objGameover.textureid);
    drawobject(&objGameover.model);
}

float player::get_playerx()
{
    return x;
}

float player::get_playery()
{
    return y;
}

float player::get_playerz()
{
    return z;
}
